<template>
	<view class="news">
	<view class="news_item" @click="navigator(item.id)" v-for="item in list" :key="item.id">
		<image :src="item.img_url"></image>
		<view class="right">
			<view class="tit">
				{{item.title}}
			</view>
			<view class="info">
				<text>发表时间:{{item.add_time | formaData}}</text>
				<text>浏览：{{item.click}}</text>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	export default{
		props:['list'], /*,, 外界传进来的值*/
		/* 过滤器 */
		filters:{
			formaData(date){
				const ndata = new Date(date)
				const year = ndata.getFullYear()
				const month = ndata.getMonth().toString().padStart(2,0)
				const day = ndata.getDay().toString().padStart(2,0)
				return year+'-'+month+'-'+day
			}
		},
		methods:{
			navigator(id){
				this.$emit('itemClick',id) /* 触发父组件的函数*/
			}
		}
	}
</script>

<style lang="scss">
	.news{
		.news_item{
			display: flex;
			padding: 10rpx 20rpx;
			border-bottom: 1px solid $shop-color;
			image{
				min-width: 200rpx;
				max-width: 200rpx;
				height: 150rpx;
			}
			.right{
				margin-left: 15rpx;
				display: flex;
				flex-direction: column; /* 将felx设置为纵向的显示方式*/
				justify-content: space-between;	/* 上下贴边靠近 */
				.tit{
					font-size: 30rpx;
				}
				.info{
					font-size: 25rpx;
					text:nth-child(2){	/* 设置info的第二个孩子text的样式 */
						margin-left: 170rpx;
					}
				}
			}
		}
	}
</style>
